package cn.touna.jss.modules.custom.carmodel.synctask;

import cn.touna.jss.common.properties.disconf.Car300Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * Created by Steve.Tao on 2017/11/20.
 */
//@Component
public class Car300Proxy {

    @Resource(name = "httpsRestTemplate")
    private RestTemplate restTemplate;

    @Autowired
    private Car300Properties config;

    public String getCarBrandList() {
        String url = build(config.getCarBrandListUrl(), "");
        return restTemplate.getForObject(url, String.class);
    }

    public String getCarSeriesList(String brandId) {
        String url = build(config.getCarSeriesListUrl(), "&brandId=" + brandId);
        return restTemplate.getForObject(url, String.class);
    }

    public String getCarModelList(String seriesId) {
        String url = build(config.getCarModelListUrl(), "&seriesId=" + seriesId);
        return restTemplate.getForObject(url, String.class);
    }

    private String build(String url, String append) {
        return new StringBuilder().append(url).append("?token=").append(config.getToken()).append(append).toString();
    }
}
